//
// dir.h
// libprotea
// Tools Library for the Protea Project / Directory management functionality
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

// Directory functions
#ifndef __PROTEA_DIR_H__
#define __PROTEA_DIR_H__

/*
	\file dir.h
	\brief OS independent routines for file searching
*/

class __EXPORT XCDirectorySearch : public XCBase {
public:
	XCDirectorySearch();
	~XCDirectorySearch();

	/**
		\brief Searches for a file
		\param name [in] Pattern to search for
		\param found [out] Match is copied here

		Searches for files matching the given pattern

		If no files are found matching the pattern, then a CToolsError is raised with 
		an ERR_OS_ERR error code.
	*/
	bool Search( const char* name, char* found );

	/**
		\brief Searches for the next file
		\param dir [in] Result of previous XCDirFirstFile call
		\param found [out] Match is copied here

		Searches for the next file

		If no files are found matching the pattern, then the result is false, otherwise
		the result is true.

		If an operating system error occurs, a CToolsError is raised with an ERR_OS_ERR
		error code.
	*/
	bool NextFile( char* found );

	/**
		\brief Close a search
		\param dir [in] Result of a previous Find call
		Close a search
	*/
	void Close();
protected:
	DIR_HANDLE_TYPE dir;
};

__EXPORT void XCChDir( char* directory );
__EXPORT DIR_HANDLE_TYPE XCDirFirstFile(const char* name, char* found);
__EXPORT bool XCDirNextFile(DIR_HANDLE_TYPE dir, char* found);
__EXPORT void XCDirClose(DIR_HANDLE_TYPE dir);

#endif
